package com.ktjiaoyu.utils;

import org.springframework.core.convert.converter.Converter;

import java.util.Date;

/**
 * String2DateConverter
 *
 * @author hyl
 * @date 2024-12-23
 */
public class String2DateConverter implements Converter<String, Date> {

    private String[] formarts={"yyyy-MM-dd" ,"yyyy/MM/dd","yyyy-MM-dd hh:mm:ss"};

    @Override
    public Date convert(String source) {
        for(String formart:formarts){
           return DateUtils.parseDate(source,formart);
        }
        return null;
    }

    public String[] getFormarts() {
        return formarts;
    }

    public void setFormarts(String[] formarts) {
        this.formarts = formarts;
    }
}
